package mobile.android.Hotel;




import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class HotelInfoActivity extends Activity{
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.select);
	        Bundle extras  = getIntent().getExtras();
	        //String Name="OK";
	        String Name  = extras.getString("name");
	        String Add  = extras.getString("add");
	        String Phone  = extras.getString("phone");
	        String Web  = extras.getString("web");
	        String Logo = extras.getString("logo");
	        final TextView textview= (TextView)findViewById(R.id.tv);
	        final Button button1 = (Button) findViewById(R.id.button1);
	        final Button button2 = (Button) findViewById(R.id.button2);
	        final Button button3 = (Button) findViewById(R.id.button3);
	        final ImageView imageView1= (ImageView)findViewById(R.id.imageView1);
	        try{
	            String url1 = Logo;
	            URL ulrn = new URL(url1);
	            HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
	            InputStream is = con.getInputStream();
	            Bitmap bmp = BitmapFactory.decodeStream(is);
	            if (null != bmp)
	                imageView1.setImageBitmap(bmp);
	            else
	                System.out.println("The Bitmap is NULL");

	            }catch(Exception e){}
	        

	        textview.setText(Name);
	        button1.setText(Add);
	        button2.setText(Phone);
	        button3.setText(Web);
	        button2.setOnClickListener(new View.OnClickListener() {
	        	public void onClick(View v){
	        		showDialog(0);
	        	}

	        });
	        button3.setOnClickListener(new View.OnClickListener() {
		        public void onClick(View v){
		        	showDialog(1);
		        }
	        });
	        button1.setOnClickListener(new View.OnClickListener() {
	        	public void onClick(View v){
	        		showDialog(2);
	        	}

	        });
	        
	 }
	 @Override
	    protected Dialog onCreateDialog(int id){
		 Bundle extras  = getIntent().getExtras();
		 final String Phone  = extras.getString("phone");
		 final String Web=extras.getString("web");
		 final String Add=extras.getString("add");
	    	switch (id){
	    	case 0:
	    		return new AlertDialog.Builder(this)
	    		.setIcon(R.drawable.phone)
	    		.setTitle(Phone)
	    		.setPositiveButton("Call",new
	    				DialogInterface.OnClickListener(){
	    			public void onClick(DialogInterface dialog,
	    			int whichButton)
	    			{
	    				Intent callIntent = new Intent(Intent.ACTION_CALL);
	    		        callIntent.setData(Uri.parse("tel:"+Phone));
	    		        startActivity(callIntent);
	    			}
	    		})
	    		.setNegativeButton("Cancel",new
	    			DialogInterface.OnClickListener() {
	    			public void onClick(DialogInterface dialog,
	    				int whichButton)
	    			{

	    			}
	    		})   							
						.create();
	    	case 1:return new AlertDialog.Builder(this)
    		.setIcon(R.drawable.chromemarks)
    		.setTitle(Web)
    		.setPositiveButton("Visit",new
    				DialogInterface.OnClickListener(){
    			public void onClick(DialogInterface dialog,
    			int whichButton)
    			{
    				Intent webIntent = new Intent(Intent.ACTION_VIEW);
    		        webIntent.setData(Uri.parse(Web));
    		        startActivity(webIntent);
    			}
    		})
    		.setNegativeButton("Cancel",new
    			DialogInterface.OnClickListener() {
    			public void onClick(DialogInterface dialog,
    				int whichButton)
    			{

    			}
    		})   							
					.create();
	    	case 2:return new AlertDialog.Builder(this)
    		.setIcon(R.drawable.maps1)
    		.setTitle("ViewMap")
    		.setPositiveButton("Map",new
    				DialogInterface.OnClickListener(){
    			public void onClick(DialogInterface dialog,
    			int whichButton)
    			{	
    				Intent i=new Intent("Map");
    				i.putExtra("add", Add);
    				startActivity(i);
    				//Intent webIntent = new Intent(Intent.ACTION_VIEW);
    		        //webIntent.setData(Uri.parse(Web));
    		        //startActivity(webIntent);
    			}
    		})
    		.setNegativeButton("Cancel",new
    			DialogInterface.OnClickListener() {
    			public void onClick(DialogInterface dialog,
    				int whichButton)
    			{

    			}
    		})   							
					.create();
	    		
					}
				return null;
					
	    	
	    }
	 /*private void call(String phone) {
		    try {
		        Intent callIntent = new Intent(Intent.ACTION_CALL);
		        callIntent.setData(Uri.parse(phone));
		        startActivity(callIntent);
		    } catch (ActivityNotFoundException activityException) {
		        Log.e("dialing-example", "Call failed", activityException);
		    }
		}*/
}
